package org.itzixi.filter;

import lombok.extern.slf4j.Slf4j;
import org.itzixi.base.BaseInfoProperties;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

@Component
@Slf4j
public class TestFilter extends BaseInfoProperties implements GlobalFilter, Ordered {
    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        log.info("TEST 当前的执行顺序order为10");
        //默认放行请求到后续的路由（服务）
        return chain.filter(exchange);
    }

    // 过滤器的优先级，数字越小，优先级越高
    @Override
    public int getOrder() {
        return 10;
    }

    /**
     * 需求：
     * 判断某个请求的ip在20秒内访问次数是否超过3次
     * 如果超过3次，则限制访问30秒
     * 等待30秒静默后，才能恢复访问
     */
}
